package bad;

import javax.swing.*;
import javax.swing.event.MouseInputAdapter;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Random;
import java.util.concurrent.LinkedBlockingQueue;

public class TakeAny {
    public static void main(String[] args) {
        Random random = new Random();

        JFrame hi = new JFrame("hi");
        hi.setSize(800,400);
        hi.setLayout(new FlowLayout());
        JButton jButton0 = new JButton("first");
        JButton jButton1 = new JButton("second");
        JButton jButton2 = new JButton("third");
        jButton0.addMouseListener(new MouseInputAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                ThreadGroup group = Thread.currentThread().getThreadGroup();
                ThreadGroup topGroup = group;

                while (group != null) {
                    topGroup = group;
                    group = group.getParent();
                }

                int estimatedSize = topGroup.activeCount() * 2;
                Thread[] slackList = new Thread[estimatedSize];

                int actualSize = topGroup.enumerate(slackList);
                Thread[] list = new Thread[actualSize];
                System.arraycopy(slackList, 0, list, 0, actualSize);
                System.out.println("Thread list size == " + list.length);
                for (Thread thread : list) {
                    System.out.println(thread.getName());
                }
            }
        });
        jButton1.addMouseListener(new MouseInputAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                hi.getContentPane().setBackground(new Color(100,random.nextInt(255),100));
                SomeTopic.debug(e.getClass().getName());
            }
        });
        jButton2.addMouseListener(new MouseInputAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                hi.getContentPane().setBackground(new Color(0,100,random.nextInt(255)));
                SomeTopic.debug(e.getClass().getName());
            }
        });
        hi.add(jButton0);
        hi.add(jButton1);
        hi.add(jButton2);
        SomeTopic.debug("main");
        hi.setVisible(true);
//        LinkedBlockingQueue


    }

}
